﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SwiftDocument.Model
{
	public class TextSpan
	{
		public int Offset { get; set; }
		public int Length { get; set; }
		public string String { get; set; }
		public string Get()
		{
			// TODO: Fill it
			return string.Empty;
		}
	}

	public class Element
	{
		public string Style { get; set; }
		public TextSpan Span { get; set; }
	}

	[DebuggerDisplay("Count = {Count}")]	
	public class ElementCollection<T> : Element, IList<T> where T : Element
	{
		public ElementCollection()
		{
			list = new List<T>();
		}

		public ElementCollection(IEnumerable<T> c)
		{
			list = new List<T>(c);
		}
				
		List<T> list;

		public int IndexOf(T item)
		{
			return list.IndexOf(item);
		}

		public void Insert(int index, T item)
		{
			list.Insert(index, item);
		}

		public void RemoveAt(int index)
		{
			list.RemoveAt(index);
		}

		public T this[int index]
		{
			get
			{
				return list[index];
			}
			set
			{
				list[index] = value;
			}
		}

		public void Add(T item)
		{
			list.Add(item);
		}

		public void Clear()
		{
			list.Clear();
		}

		public bool Contains(T item)
		{
			return list.Contains(item);
		}

		public void CopyTo(T[] array, int arrayIndex)
		{
			list.CopyTo(array, arrayIndex);
		}

		public int Count
		{
			get { return list.Count; }
		}

		public bool IsReadOnly
		{
			get { return false; }
		}

		public bool Remove(T item)
		{
			return list.Remove(item);
		}

		public IEnumerator<T> GetEnumerator()
		{
			return list.GetEnumerator();
		}

		System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
		{
			return list.GetEnumerator();
		}
	}

	public class Document : Element
	{
		public List<Block> Blocks { get; set; }

		public Document()
		{
			Blocks = new List<Block>();
		}
	}

	public class Block : Element
	{
	}

	public class Empty : Block
	{
	}

	public class Paragraph : Block
	{
		public Inlines Content { get; set; }
	}

	public class Inline : Element
	{
		public string Text { get; set; }
	}

	public class Str : Inline
	{
	}

	public class Space : Inline
	{		
	}

	public class Emph : Inline
	{
	}

	public class Underline : Inline
	{
	}

	public class Strike : Inline
	{
	}

	public class Image : Inline
	{
	}

	public class Link : Inline
	{
	}

	public class Reference : Inline
	{
	}

	public class Inlines : ElementCollection<Inline>
	{
		public Inlines()
		{
		}

		public Inlines(IEnumerable<Inline> c)
			: base(c)
		{

		}
	}

	public class Header : Block
	{
		public int Level { get; set; }
		public Inlines Content { get; set; }
	}

	public class Table : Block
	{
		public List<ColumnDefinition> ColumDefinitions { get; set; }
		public List<Row> Rows { get; set; }
	}

	public class Row : Element
	{
		public List<Cell> Cells { get; set; }
	}

	public class Cell : Element
	{
		public Inlines Content { get; set; }
	}

	public enum HorizontalAlignment
	{
		Left, Right, Center, Justify
	}

	public class ColumnDefinition : Element
	{
		public HorizontalAlignment Alignment { get; set; }
		public Inlines Header { get; set; }
	}

}
